/*
 * @Author: wuzhen
 * @Date: 2019-01-25 15:45:25
 * @LastEditors: wuzhen
 * @LastEditTime: 2019-10-25 19:23:02
 * @Description: 全局方法
 */
/**
 * @description 绑定事件 on(element, event, handler)
 */
export const onBind = (element, event, handler) => {
  if (document.addEventListener) {
    if (element && event && handler) {
      element.addEventListener(event, handler, false);
    }
  } else {
    if (element && event && handler) {
      element.attachEvent("on" + event, handler);
    }
  }
};

/**
 * @description 解绑事件 off(element, event, handler)
 */
export const offBind = (element, event, handler) => {
  if (document.removeEventListener) {
    if (element && event) {
      element.removeEventListener(event, handler, false);
    }
  } else {
    if (element && event) {
      element.detachEvent("on" + event, handler);
    }
  }
};

// 验证电话号码格式
export const checkPhone = tel => {
  if (
    /^1[3456789]\d{9}$/.test(tel) ||
    /^([0-9]{3,4})?-[0-9]{7,8}$/.test(tel) ||
    /^[48]00\d{8}$/.test(tel)
  ) {
    return true;
  }
  return false;
};
